﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;

namespace TimeSplicer.App
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            Bootstrapper bootstrapper = new Bootstrapper();
            bootstrapper.Run();

            // todo: show default views and set up session -- need to set up session first 
            IUnityContainer _container = ServiceLocator.Current.GetInstance<IUnityContainer>();
            var _sessionService = _container.Resolve<TimeSplicerModule.Security.ISessionService>();

            var _session = _sessionService.Get(Environment.UserName);

            if (_session.User == null)
            {

                var l = new TimeSplicerModule.Controllers.LoginController();
                l.NavigateToView();
            }
            else
            {
                // register session
                _container.RegisterInstance<TimeSplicerModule.Security.ISession>(_session);

                var c = new NavigationModule.Controllers.TopNavigationController();
                c.Navigate();


                if (_session.User.ApplicationRole.Hierarchy == 0)
                {
                    var d = new DeveloperModule.Controllers.UserSelectionController();
                    d.NavigateToView(Infrastucture.RegionNames.DeveloperUserSelectionRegion);
                }
            }



        }
    }
}
